package com.zzyl.controller.customer;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.ReservationDto;
import com.zzyl.entity.TimeCount;
import com.zzyl.service.CustomerReservationService;
import com.zzyl.vo.ReservationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/customer/reservation")
@Api(tags = "客户预约管理")
public class CustomerReservationController extends BaseController {
    @Autowired
    private CustomerReservationService customerReservationService;

    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public ResponseResult<Integer> getCancelledReservationCount() {
        Integer count = customerReservationService.getCancelledReservationCount();
        return success(count);
    }

    @GetMapping("/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public ResponseResult<TimeCount> getCountByTimeCount(Long time) {
        List<TimeCount> countList = customerReservationService.getCountByTimeCount(LocalDateTimeUtil.of(time));
        return success(countList);
    }

    @PostMapping
    @ApiOperation("添加预约")
    public ResponseResult addReservation(@RequestBody ReservationDto reservationDto) {
        customerReservationService.addReservation(reservationDto);
        return ResponseResult.success();
    }

    @GetMapping("/page")
    @ApiOperation("分页查询预约")
    public ResponseResult<PageResponse<ReservationVo>> getByPage(
            @ApiParam(value = "预约状态，0：待报道，1：已完成，2：取消，3：过期") Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageResponse<ReservationVo> result = customerReservationService.getByPage(status, pageNum, pageSize);
        return success(result);
    }
    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public ResponseResult cancel(@PathVariable Long id) {
        customerReservationService.cancel(id);
        return ResponseResult.success();
    }
}